package leecode

import "math"

type MinStackM struct {
	stack    []int
	minStack []int //栈顶元素存放最小值
}

/** initialize your data structure here. */
func ConstructorM() MinStackM {
	minStack := []int{math.MaxInt}
	return MinStackM{
		stack:    make([]int, 0),
		minStack: minStack,
	}
}

func (this *MinStackM) Push(x int) {
	this.stack = append(this.stack, x)
	top := this.minStack[len(this.minStack)-1]
	this.minStack = append(this.minStack, min(top, x))
}

func (this *MinStackM) Pop() {
	this.stack = this.stack[:len(this.stack)-1]
	this.minStack = this.minStack[:len(this.minStack)-1]
}

func (this *MinStackM) Top() int {
	return this.stack[len(this.stack)-1]
}

func (this *MinStackM) GetMin() int {
	return this.minStack[len(this.minStack)-1]
}
